package com.chinackts.customsdeclarations.repository.redis;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author Lianhong
 * @since 2021/11/1
 * 报关单加签字符串仓库
 */
@Repository
public class DecDetailSignRepository {

    @Resource
    private StringRedisTemplate redisTemplate1;

    private static final String KEY = "sign:%s";

    /**
     * @param entryId 报关单号
     */
    public String getDetailSign(String entryId) {
        ValueOperations<String, String> ops = this.redisTemplate1.opsForValue();
        String sign = ops.get(String.format(KEY, entryId));
        if (StringUtils.isEmpty(sign)) return null;
        return sign;
    }

    /**
     * @param entryId 报关单号
     */
    public void saveDetailSign(String entryId, String sign) {
        ValueOperations<String, String> ops = this.redisTemplate1.opsForValue();
        ops.set(String.format(KEY, entryId), sign);
    }
}
